//
//  AppDelegate.swift
//  SYWeibo
//
//  Created by Saya on 16/4/6.
//  Copyright © 2016年 黄金果. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window?.backgroundColor = UIColor.whiteColor()
        
//        window?.rootViewController = UINavigationController(rootViewController: SYComposeVC())
//        window?.rootViewController = UINavigationController(rootViewController:SYPicturePickVC())
        window?.rootViewController = defaultRootController()
        //添加一个通知,设置为nil意味广播
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "switchRootVC:", name: SYSwitchRootController, object: nil)
        
        window?.makeKeyAndVisible()
        setNavTextColor()
        return true
    }
    
    //提供一个方法设置navigationBar的字体颜色
    private func setNavTextColor () {
        //由于applicationdelegate,比较早,所以在这边设置可以起到效果
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
    }
    
    private func defaultRootController()->UIViewController{
        return SYVIewModel.viewModel.isLogin ? SYWelcomVC() : SYMainController()
    }
    
    @objc private func switchRootVC (notify:NSNotification){
        window?.rootViewController = notify.object?.isEqual("SYMainController")==true ?
        SYMainController() : SYWelcomVC()

    }
    
    deinit {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    
    
}
















